package com.demo;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateDemo {

	public static void main(String[] args) throws ParseException {
		String [] data = {"马云","马化腾","李彦宏","刘强东"};
		for (String p : data) {
			System.out.println(p);
		}
	}

	private static void test6() {
		BigDecimal b1 = new BigDecimal("0.1");
		BigDecimal b2 = new BigDecimal("0.01");
		BigDecimal b3 = b1.subtract(b2);
		System.out.println(b3);
	}

	private static void test5() {
		Calendar c = Calendar.getInstance();//获取当前时间
		c.set(Calendar.DATE, 1);//设置日期为1号
		int start=c.get(Calendar.DAY_OF_WEEK);//获得1号是星期几
		//获得当前月的最大日期数
		int maxDay=c.getActualMaximum(Calendar.DATE);
		//输出标题
		System.out.println("星期日 星期一 星期二 星期三 星期四 星期五 星期六");
		//输出开始的空格
		for(int i=1;i<start; i++) {
			System.out.print("\t");
		}
		//输出该月中的所有日期
		for(int i=1; i<=maxDay;i++) {
			//输出日期数字
			if(i<10)
			System.out.format("%10d",i);
			else
				System.out.format("%9d",i);
			//判断是否换行
			if( (start+i-1)%7 == 0 ) {
				System.out.println();
			}
		}
	}

	private static void test4() {
		Calendar c3 = Calendar.getInstance();
		c3.add(Calendar.DATE, -1);
		int year = c3.get(Calendar.YEAR);
		int month = c3.get(Calendar.MONTH)+1;
		int date = c3.get(Calendar.DATE);
		System.out.println(year + "年" + month + "月" + date + "日");
	}

	private static void test3() throws ParseException {
		String birthday = "1990年08月01日 12:22:33";
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
		Date date = sdf.parse(birthday);
		System.out.println(date);
	}

	private static void test2() {
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
		String str = sdf.format(date);
		System.out.println(str);
	}

	private static void test1() {
		Date date = new Date();
		System.out.println(date);
		long time = date.getTime();
		System.out.println("毫秒数:" + time);
		// 根据毫秒数创建新的日期对象 1507618047365+1000000
		Date date2 = new Date(1507628047365L);
		boolean after = date2.after(date);
		System.out.println(after);
	}

}
